from openpyxl import load_workbook
from openpyxl import Workbook
import datetime

def readExcelData():
    wb=load_workbook('学习课程.xlsx')
    sheet = wb['Sheet1']
    dict = {}
    cellA=sheet['A']
    dataA = []
    for cell in cellA[1:]:
        dataA.append(cell.value)
    dict['高等数学'] = dataA

    cellB = sheet['B']
    dataB = []
    for cell in cellB[1:]:
        dataB.append(cell.value)
    dict['线性代数'] = dataB

    cellC = sheet['C']
    dataC = []
    for cell in cellC[1:]:
        dataC.append(cell.value)
    dict['英语'] = dataC

    cellD = sheet['D']
    dataD = []
    for cell in cellD[1:]:
        dataD.append(cell.value)
    dict['数据结构'] = dataD

    wb.close()
    return dict


def writeExcel(dict):
    # 星期几的中文映射
    weekdays = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
    # 获取当前日期
    today = datetime.datetime(2025,4,16)

    # 创建一个新的工作簿
    wb = Workbook()
    # 获取默认的工作表
    ws = wb.active

    dataA = dict['高等数学']
    dataB = dict['线性代数']
    dataC = dict['英语']
    dataD = dict['数据结构']

    ws['A1'] = '星期'
    ws['B1'] = "时间"
    ws['C1'] = "科目"
    ws['D1'] = "任务"
    ws['E1'] = "课后课"
    ws['F1'] = "完成情况"

    row = 2
    indexA = 0
    indexB=0
    indexC=0
    indexD=0
    for i in range(100):
        future_date = today + datetime.timedelta(days=i+1)
        date_str = future_date.strftime('%Y-%m-%d')
        weekday_str = weekdays[future_date.weekday()]  # 获取中文星期几

        if weekday_str == '星期六':
            for j in range(9):
                if j + 1 == 1:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 10:00:00"
                    ws['C'+str(row)] = "高等数学"
                    ws['D'+str(row)] = dataA[indexA] if indexA<=len(dataA)-1 else ""
                    indexA = indexA + 1
                    row = row + 1
                if j + 1 == 2:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 11:00:00"
                    ws['C'+str(row)] = "高等数学"
                    ws['D'+str(row)] = dataA[indexA] if indexA<=len(dataA)-1 else ""
                    indexA = indexA + 1
                    row = row + 1
                if j + 1 == 3:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 12:00:00"
                    ws['C'+str(row)] = "高等数学"
                    ws['D'+str(row)] = dataA[indexA] if indexA<=len(dataA)-1 else ""
                    indexA = indexA + 1
                    row = row + 1
                if j + 1 == 4:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 15:00:00"
                    ws['C'+str(row)] = "线性代数"
                    ws['D'+str(row)] = dataB[indexB] if indexB<=len(dataB)-1 else ""
                    indexB = indexB + 1
                    row = row + 1
                if j + 1 == 5:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 16:00:00"
                    ws['C'+str(row)] = "线性代数"
                    ws['D'+str(row)] = dataB[indexB] if indexB<=len(dataB)-1 else ""
                    indexB = indexB + 1
                    row = row + 1
                if j + 1 == 6:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 17:00:00"
                    ws['C'+str(row)] = "英语"
                    ws['D'+str(row)] = dataC[indexC] if indexC<=len(dataC)-1 else ""
                    indexC = indexC + 1
                    row = row + 1
                if j + 1 == 7:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 18:30:00"
                    ws['C'+str(row)] = "英语"
                    ws['D'+str(row)] = dataC[indexC] if indexC<=len(dataC)-1 else ""
                    indexC = indexC + 1
                    row = row + 1
                if j + 1 == 8:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 20:00:00"
                    ws['C'+str(row)] = "数据结构"
                    ws['D'+str(row)] = dataD[indexD] if indexD<=len(dataD)-1 else ""
                    indexD = indexD + 1
                    row = row + 1
                if j + 1 == 9:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 21:00:00"
                    ws['C'+str(row)] = "数据结构"
                    ws['D'+str(row)] = dataD[indexD] if indexD<=len(dataD)-1 else ""
                    indexD = indexD + 1
                    row = row + 1
        elif weekday_str == '星期日':
            ws['A' + str(row)] = weekday_str
            ws['B'+str(row)] = date_str
            ws['C'+str(row)] = "休息"
            ws['D'+str(row)] = "休息"
            ws['E'+str(row)] = "休息"
            ws['F'+str(row)] = "休息"
            row =row+1
        else:
            for j in range(8):
                if j+1 == 1:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)]=date_str+" 20:00:00"
                    ws['C'+str(row)]="高等数学"
                    ws['D'+str(row)]=dataA[indexA] if indexA<=len(dataA)-1 else ""
                    indexA=indexA+1
                    row = row+1
                if j + 1== 2:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 20:30:00"
                    ws['C'+str(row)] = "高等数学"
                    ws['D'+str(row)] = dataA[indexA] if indexA<=len(dataA)-1 else ""
                    indexA = indexA + 1
                    row = row + 1
                if j + 1== 3:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 22:00:00"
                    ws['C'+str(row)] = "线性代数"
                    ws['D'+str(row)] = dataB[indexB] if indexB<=len(dataB)-1 else ""
                    indexB = indexB + 1
                    row = row + 1
                if j + 1== 4:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 23:00:00"
                    ws['C'+str(row)] = "线性代数"
                    ws['D'+str(row)] = dataB[indexB] if indexB<=len(dataB)-1 else ""
                    indexB = indexB + 1
                    row = row + 1
                if j + 1== 5:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 23:30:00"
                    ws['C'+str(row)] = "英语"
                    ws['D'+str(row)] = dataC[indexC] if indexC<=len(dataC)-1 else ""
                    indexC = indexC + 1
                    row = row + 1
                if j + 1== 6:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 00:00:00"
                    ws['C'+str(row)] = "英语"
                    ws['D'+str(row)] = dataC[indexC] if indexC<=len(dataC)-1 else ""
                    indexC = indexC + 1
                    row = row + 1
                if j + 1== 7:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 00:30:00"
                    ws['C'+str(row)] = "数据结构"
                    ws['D'+str(row)] = dataD[indexD] if indexD<=len(dataD)-1 else ""
                    indexD = indexD + 1
                    row = row + 1
                if j + 1== 8:
                    ws['A' + str(row)] = weekday_str
                    ws['B'+str(row)] = date_str + " 01:00:00"
                    ws['C'+str(row)] = "数据结构"
                    ws['D'+str(row)] = dataD[indexD] if indexD<=len(dataD)-1 else ""
                    indexD = indexD + 1
                    row = row + 1

    wb.save('学习计划.xlsx')


if __name__ == '__main__':
    dict=readExcelData()
    writeExcel(dict)